package com.auxgroup.smarthome.inner.controller;

import com.auxgroup.bridge.app.inner.dto.AppFilterFaultDto;
import com.auxgroup.bridge.app.inner.vo.AppFilterFaultVo;
import com.auxgroup.smarthome.inner.service.AppFilterFaultService;
import com.auxgroup.smarthome.syscode.BusinessCode;
import com.auxgroup.smarthome.web.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 滤网故障类
 * Created by lixiaoxiao on 17-8-14.
 */
@Api(description = "滤网清洗", tags = "滤网故障")
@RestController
public class AppFilterFaultController {

    @Autowired
    private AppFilterFaultService appFilterFaultService;

    @ApiOperation(value = "滤网清洗", notes = "滤网故障--滤网清洗")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户id", paramType = "query", dataType = "string", required = true)
    })
    @RequestMapping(value = "/confirm_filter_washed", method = RequestMethod.POST)
    public ApiResponse confirmFilterWashed(@RequestBody AppFilterFaultDto appFilterFaultDto,
                                           @RequestParam(value = "uid") String uid) {
        Boolean isOk = appFilterFaultService.confirmFilterWashed(appFilterFaultDto,uid);
        if(isOk) {
            return ApiResponse.ok(isOk);
        }else{
            return ApiResponse.prompt(BusinessCode.APP_FILTER_FAULT_NOT_FOUND);
        }
    }

    /**
     * 滤网故障
     * @param mac
     * @return
     */
    @ApiOperation(value = "滤网故障")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mac", value = "设备mac", paramType = "query", dataType = "string", required = true)
    })
    @RequestMapping(value = "/filter_fault", method = RequestMethod.GET)
    public ApiResponse<AppFilterFaultVo> getFilterFault(@RequestParam(required = true) String mac) {
        AppFilterFaultVo appFilterFaultVo = appFilterFaultService.getFilterFalut(mac);
        return ApiResponse.ok(appFilterFaultVo);
    }

    @ApiOperation(value = "根据mac获取滤网故障信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mac", value = "设备mac", paramType = "query", dataType = "string", required = true),
    })
    @GetMapping(value = "/filter_fault_data")
    public ApiResponse<AppFilterFaultVo> getFilterFaultData(@RequestParam(value = "mac") String mac) {
        AppFilterFaultVo appFilterFaultVo = appFilterFaultService.getFilterFalutData(mac);
        return ApiResponse.ok(appFilterFaultVo);
    }

    @ApiIgnore
    @ApiOperation(value = "滤网时间计算", notes = "滤网故障--滤网时间计算")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mac", value = "设备mac", paramType = "form", dataType = "string", required = true),
            @ApiImplicitParam(name = "realOnOff", value = "开关机", paramType = "form", dataType = "Boolean", required = true),
            @ApiImplicitParam(name = "fromReport", value = "十分钟上报", paramType = "form", dataType = "Boolean", required = false)
    })
    @RequestMapping(value = "/filter_time", method = RequestMethod.POST)
    public ApiResponse getFilterFalutData(@RequestParam(value = "mac") String mac, @RequestParam(value = "realOnOff") Boolean realOnOff,
                                     @RequestParam(value = "fromReport") Boolean fromReport) {
        appFilterFaultService.calculateTime(mac, realOnOff, fromReport);
        return ApiResponse.ok(true);
    }
}
